/*
 * logo.c
 *
 * Created on Sep 22, 2013
 *              Author: Jospeh DeLong
 *
 */

#include <stdio.h>
#include <dos.h>

/*
 * LOGO function
 * Written by Joseph DeLong
 * Displays an animated ASCII logo of a running horse, as well as a final load screen, with the name of the OS
 * parameters: NONE
 * returns: an Integer representing either 0 (normal operation/termination) or a non-zero number (error code)
 * TODO: Change all printf() statements to sys_req() statements
 * TODO: Change all delay() statements to sys_req() statements?
 */
int logo(void) {
        //open all logo files
        int h,i,j,k;
        FILE *logo1 = fopen("logo01","r");
        FILE *logo2 = fopen("logo02","r");
        FILE *logo3 = fopen("logo03","r");
        FILE *logo4 = fopen("logo04","r");
        FILE *logo5 = fopen("logo05","r");
        FILE *logo6 = fopen("logo06","r");
        FILE *logo7 = fopen("logo07","r");
        FILE *logo8 = fopen("logo08","r");
        FILE *logoF = fopen("logoF","r");
        //make FILE array
        FILE *logos[8];
        logos[0] = logo1;
        logos[1] = logo2;
        logos[2] = logo3;
        logos[3] = logo4;
        logos[4] = logo5;
        logos[5] = logo6;
        logos[6] = logo7;
        logos[7] = logo8;
        //set up for iteration
        for (h = 0; h < 4; h++) { //number of animations
                //set seek position to start of files
                fseek(logo1,0,SEEK_SET);
                fseek(logo2,0,SEEK_SET);
                fseek(logo3,0,SEEK_SET);
                fseek(logo4,0,SEEK_SET);
                fseek(logo5,0,SEEK_SET);
                fseek(logo6,0,SEEK_SET);
                fseek(logo7,0,SEEK_SET);
                fseek(logo8,0,SEEK_SET);
                for(i = 0; i < 8; i++) { //number of frames
                        for(j = 0; j < 25; j++) { //number of rows in each frame
                                for(k = 0; k < 80; k++) { //number of characters in each row
                                        printf("%c", fgetc(logos[i]));
                                }
                                fgetc(logos[i]);//this should clear the newline character from being captured
                        }
                        delay(250); //wait a quarter of a second after each frame <dos.h>
                }
        }
        //display final load screen
        fseek(logoF,0,SEEK_SET);
        for(j = 0; j < 25; j++) { //number of rows
                for(k = 0; k < 80; k++) { //number of characters in each row
                        printf("%c", fgetc(logoF));
                }
                fgetc(logos[i]);//this should clear the newline character from being captured
        }
        delay(5000); //wait 5 seconds <dos.h>
        //close all logo files
        fclose(logo1);
        fclose(logo2);
        fclose(logo3);
        fclose(logo4);
        fclose(logo5);
        fclose(logo6);
        fclose(logo7);
        fclose(logo8);
        fclose(logoF);
        //exit
        return 0;
}
